import { _decorator, EditBox, Input, Node } from "cc";
import { BasicUI } from "../../Init/Basic/BasicUI";
import { UIEnum } from "../../Init/SystemUI/UIEnum";
import { UISystem } from "../../Init/SystemUI/UISystem";
import BindUserManager from "../../[模块]/绑定用户/BindUserManager";

const { ccclass, property } = _decorator;
@ccclass('TaskBindPhoneUI')
export class TaskBindPhoneUI extends BasicUI {
    @property(Node)
    btn_cancel: Node = null;

    @property(Node)
    btn_confirm: Node = null;

    @property(EditBox)
    txt_input_1: EditBox = null;

    @property(EditBox)
    txt_input_2: EditBox = null;

    protected onEnable(): void {
        this.btn_cancel.on(Input.EventType.TOUCH_END, this.close, this);
        this.btn_confirm.on(Input.EventType.TOUCH_END, this.onConfirm, this);
    }


    public async onConfirm() {
        let txt1 = this.txt_input_1.string;
        let txt2 = this.txt_input_2.string;
        let success = await BindUserManager.bind({
            username: txt1,
            remark: txt2,
        });
        if (success) {
            this.close();
        }
    }

    public close() {
        this.onCloseBtnClick();
    }

    onCloseBtnClick() {
        UISystem.hideUI(UIEnum.TaskBindPhoneUI);
    }
}